package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplicationfile.LindiTradeApplicationFileQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationfile.LindiTradeApplicationFileVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiTradeApplicationFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_交易申请文件管理")
@RequestMapping("/lindi/tradeApplicationFile")
public class LindiTradeApplicationFileController{

    @Autowired
    private LindiTradeApplicationFileService service;

    @PostMapping("/addTradeApplicationFile")
    @Operation(summary = "添加交易申请文件")
    public R<?> addTradeApplicationFile(@RequestBody @Validated(Add.class)
                                        LindiTradeApplicationFileVO fileVO){
        service.addTradeApplicationFile(fileVO);
        return R.ok();
    }

    @DeleteMapping("/deleteTradeApplicationFileByTradeApplicationFileId")
    @Operation(summary = "删除交易申请文件 -> 根据交易申请文件ID删除")
    public R<?> deleteTradeApplicationFileByTradeApplicationFileId(
            @RequestParam("tradeApplicationFileId")
            @NotNull(message = "交易申请文件ID不能为空")
            @Parameter(name = "tradeApplicationFileId", required = true, description = "交易申请文件ID")
            Long tradeApplicationFileId){
        service.deleteTradeApplicationFileByTradeApplicationFileId(tradeApplicationFileId);
        return R.ok();
    }

    @PutMapping("/updateTradeApplicationFileByTradeApplicationFileId")
    @Operation(summary = "修改交易申请文件")
    public R<?> updateTradeApplicationFileByTradeApplicationFileId(
            @RequestBody @Validated(Update.class) LindiTradeApplicationFileVO fileVO){
        service.updateTradeApplicationFileByTradeApplicationFileId(fileVO);
        return R.ok();
    }

    @GetMapping("/getPageTradeApplicationFileList")
    @Operation(summary = "查询交易申请文件列表(分页)")
    public R<PageResp<LindiTradeApplicationFileVO>> getPageTradeApplicationFileList(
            @RequestBody LindiTradeApplicationFileQueryVO queryVO){
        return R.ok(service.getPageTradeApplicationFileList(queryVO));
    }

    @GetMapping("/getTradeApplicationFileByTradeApplicationFileId/{tradeApplicationFileId}")
    @Operation(summary = "根据交易申请文件ID查询交易申请文件")
    public R<LindiTradeApplicationFileVO> getTradeApplicationFileByTradeApplicationFileId(
            @PathVariable(value = "tradeApplicationFileId")
            @NotNull(message = "交易申请文件ID不能为空")
            @Parameter(name = "tradeApplicationFileId", description = "交易申请文件ID", required = true)
            Long tradeApplicationFileId){
        return R.ok(service.getTradeApplicationFileByTradeApplicationFileId(
                tradeApplicationFileId));
    }

    @GetMapping("/getTradeApplicationFilesByApplicationId/{tradeApplicationId}")
    @Operation(summary = "根据交易申请ID查询文件列表")
    public R<List<LindiTradeApplicationFileVO>> getTradeApplicationFilesByApplicationId(
            @PathVariable(value = "tradeApplicationId")
            @NotNull(message = "交易申请ID不能为空")
            @Parameter(name = "tradeApplicationId", description = "交易申请ID", required = true)
            Long tradeApplicationId){
        return R.ok(service.getTradeApplicationFilesByApplicationId(
                tradeApplicationId));
    }

    @PostMapping("/deleteTradeApplicationFileByFileId")
    @Operation(summary = "删除交易申请文件 -> 根据文件ID删除")
    public R<?> deleteTradeApplicationFileByFileId(
            @RequestParam("fileId")
            @NotNull(message = "文件ID不能为空")
            @Parameter(name = "fileId", description = "文件ID", required = true)
            Long fileId){
        service.deleteFileByFileId(fileId);
        return R.ok();
    }
}